/**
 * copy file use bufferedReader and BufferedWriter
 */
package cn.netjava.softkid.chapter07;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 * @author softkid
 */
public class FileCopy {
	/**
	 * copy file use bufferedReader and BufferedWriter
	 * @throws IOException
	 */
	public void copyFile() throws IOException
	{
		InputStreamReader reader = new InputStreamReader(new FileInputStream("D:copy.java"));
		OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("D:copy2.java"));
		BufferedReader bufReader = new BufferedReader(reader);
		BufferedWriter bufWriter = new BufferedWriter(writer);
		String str=null;
		while((str=bufReader.readLine())!=null)
		{
			bufWriter.write(str);
		}
		bufWriter.flush();
		reader.close();
		writer.close();
		
	}
	
	/**
	 * main method	
	 * @param args
	 */
	public static void main(String args[])
	{
		FileCopy fc = new FileCopy();
		
		//time of start copy
		long start = System.currentTimeMillis();
		try {
			fc.copyFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
		//output cost time of copy
		System.out.println(System.currentTimeMillis()-start);
	}
}
